<template>
  <div>
    <!-- 添加公司 -->
    <el-button icon="el-icon-plus" type="success" @click="add(0)">添加公司</el-button>
    <!-- 表格 -->
    <el-table :data="list">
      <el-table-column label="公司" width="130px">
        <template slot-scope="scope">{{scope.row.enterprise.ename}}</template>
      </el-table-column>
      <el-table-column prop="salary" label="薪资" width="130px">
        <template slot-scope="scope">
          <el-tooltip class="item" effect="dark" placement="right-end">
            <template #content>
              <p>{{scope.row.salarymin}}-{{scope.row.salarymax}}</p>
            </template>
            <el-button type="small">薪资</el-button>
          </el-tooltip>
        </template>
      </el-table-column>
      <el-table-column prop="address" label="工作地" width="120px"></el-table-column>
      <el-table-column prop="zname" label="职位名称" width="120px"></el-table-column>
      <el-table-column prop="treatment" label="福利待遇" width="120px"></el-table-column>
      <el-table-column label="状态">
        <template slot-scope="scope">
          <el-tag v-if="scope.row.status == 0" effect="dark" type="info">未审核</el-tag>
          <el-tag v-else effect="dark" type="success">已审核</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button v-if="scope.row.status == 0" size="mini" @click="frame(scope.row,1)">通过审核</el-button>
          <el-button v-else size="mini" type="danger" @click="frame(scope.row,0)">取消审核</el-button>
          <el-button type="danger" size="mini" @click="sc(scope.row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <!-- 分页器 -->
    <el-pagination
      background
      layout="prev, pager, next"
      :total="total"
      :page-size="pageSize"
      :current-page="page"
      @current-change="gopage"
      hide-on-single-page
    ></el-pagination>
  </div>
</template>

<script>
export default {
  data() {
    return {
      pageSize: 8,
      page: 1,
      total: 100,
      /* list: [
        {
          Eid: "中国移动",
          Salary: 1000,
          Address: "太原",
          Zname: "前端",
          Treatment: "包吃管住",
          state: 0,
        },
        {
          Eid: "中国移动",
          Salary: 1000,
          Address: "太原",
          Zname: "前端",
          Treatment: "包吃管住",
        },
        {
          Eid: "中国移动",
          Salary: 1000,
          Address: "太原",
          Zname: "前端",
          Treatment: "包吃管住",
          state: 0,
        },
      ], */
      list: [],
      status: 0,
      stu: "",
    };
  },
  created() {
    this.status = this.$route.params.status;
    this.getDate();
  },
  methods: {
    // 查询数据
    getDate() {
      this.$http({
        url: "admin/recruit/getAll",
        method: "get",
        params: {
          page: this.page,
          pageSize: this.pageSize,
        },
      }).then((res) => {
        console.log(res);
        this.list = res;
        /* this.page = res.page;
            this.pageSize = res.pageSize;
            this.total = res.total; */
      });
    },
    gopage(page) {
      this.page = page;
      this.getDate();
    },
    add(id) {
      this.$router.push({
        path: "/recruit/add",
        query: {
          id,
        },
      });
    },
    sc(item) {
      // 删除信息
      this.$confirm(`确定要删除${item.eid}吗？`, "提示", {
        confirmButtonText: "删除",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.$http({
            url: "enterprise/recruit/delete",
            method: "get",
            params: {
              zid: item.zid,
            },
          }).then((res) => {
            this.$message({
              type: res.code == 200 ? "success" : "error",
              message: res.msg,
            });
            if (res.code == 200) {
              this.getDate();
            }
          });
        })
        .catch(() => {});
    },
    frame(item, status) {
      console.log(status);
      if (status == 1) {
        this.stu = "通过审核";
      } else {
        this.stu = "取消审核";
      }
      this.$confirm(`确定要${this.stu}吗？`, "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          //切换审核状态
          this.$http({
            url: "admin/recruit/update",
            method: "get",
            params: {
              zid: item.zid,
              status,
            },
          }).then((res) => {
            this.getDate();
            this.$message({
              type: res.integer == 1 ? "error" : "success",
              message: "修改审核状态成功",
            });
            if (res.integer == 1) {
              this.getDate();
            }
          });
        })
        .catch(() => {});
    },
  },
};
</script>

<style scoped>
.el-table{
  width: 100%;
  margin-bottom: 20px;
}
</style>